*****************************
*** GENDER GAP ANALYSIS *****
*** QUINN M. ALBAUGH ********
*** APRIL 2024 VERSION ***
*****************************

*** SET WORKING DIRECTORY
clear all

*** CHANGE SETTINGS FOR GRAPHS
set more off, permanently
grstyle init
grstyle set plain, horizontal nogrid
graph set window fontface "Helvetica"

*** IMPORT DATA
use "${here}GenderGapAnalysis.dta", clear

***********************************************************
*** TABLE 1: UNWEIGHT AND WEIGHTED % BY GENDER IDENTITY ***
***********************************************************

tab genderid
tab genderid [aweight = cps21_weight_general_all]

****************************************************************
*** MINOR RECODES AND CLEANING FOR MAKING TABLES AND FIGURES ***
****************************************************************

drop if genderid == 4

recode partyid (7=6)
recode partyid (8=7)
label define parties3 1 "Liberal" 2 "Conservative" 3 "NDP" 4 "BQ" 5 "Green" 6 "Other" 7 "None"
label values partyid parties3

tab partyid, gen(pid_)

recode pt (12=11) (13=11)

**************************************
*** FIGURE 1: PARTY IDENTIFICATION ***
**************************************

*** LIBERAL
preserve
drop if genderid == .
drop if pid_1 == .

tab genderid pid_1 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN = sum(cps21_weight_general_all)
by genderid, sort: gen liberal_w = pid_1 * cps21_weight_general_all
by genderid, sort: egen liberal_w_sum = sum(liberal_w)
by genderid, sort: gen p_hat = liberal_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 1.2 if genderid == 3
replace GenderID = 2.2 if genderid == 2
replace GenderID = 3.2 if genderid == 1

gen Party = 1
save "${here}LiberalPID.dta", replace
restore

*** CONSERVATIVE
preserve
drop if genderid == .
drop if pid_2 == .

tab genderid pid_2 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN= sum(cps21_weight_general_all)
by genderid, sort: gen conservative_w = pid_2 * cps21_weight_general_all
by genderid, sort: egen conservative_w_sum = sum(conservative_w)
by genderid, sort: gen p_hat = conservative_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 1 if genderid == 3
replace GenderID = 2 if genderid == 2
replace GenderID = 3 if genderid == 1

gen Party = 2

drop genderid
save "${here}ConservativePID.dta", replace
restore

*** NDP
preserve
drop if genderid == .
drop if pid_3 == .

tab genderid pid_3 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN= sum(cps21_weight_general_all)
by genderid, sort: gen ndp_w = pid_3 * cps21_weight_general_all
by genderid, sort: egen ndp_w_sum = sum(ndp_w)
by genderid, sort: gen p_hat = ndp_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 0.8 if genderid == 3
replace GenderID = 1.8 if genderid == 2
replace GenderID = 2.8 if genderid == 1

gen Party = 3

drop genderid
save "${here}NDPPID.dta", replace
restore

preserve
use "${here}LiberalPID.dta", clear
append using "${here}ConservativePID.dta"
append using "${here}NDPPID.dta"

graph twoway ///
	(scatter GenderID p_hat if Party == 1, mcolor(gs12) msymbol(Dh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(scatter GenderID p_hat if Party == 2, mcolor(gs6) msymbol(Sh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(scatter GenderID p_hat if Party == 3, mcolor(black) msymbol(Oh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike lower90 upper90 GenderID if Party == 1, lcolor(gs12) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 1, lcolor(gs12) lwidth(medthin) horizontal) ///
	(rspike lower90 upper90 GenderID if Party == 2, lcolor(gs6) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 2, lcolor(gs6) lwidth(medthin) horizontal) ///
	(rspike lower90 upper90 GenderID if Party == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 3, lcolor(black) lwidth(medthin) horizontal), ///
	yscale(range(0.75 3.25) titlegap(2)) ///
	ytitle("") ///
	ylabel(1 "Nonbinary" 2 "Woman" 3 "Man", labsize(medsmall)) ///
	xscale(range(0 100) titlegap(2)) ///
	xlabel(0(25)100) ///
	legend(order(1 2 3) label(1 "Liberal") label(2 "Conservative") label(3 "NDP")  position(3))
graph export "${here}GenderPID_Weighted.eps", replace
restore

******************************************
*** FIGURE 2: WEIGHTED VOTE INTENTIONS ***
******************************************

*** LIBERAL
preserve
drop if genderid == .
drop if vote_1 == .

tab genderid vote_1 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN = sum(cps21_weight_general_all)
by genderid, sort: gen liberal_w = vote_1 * cps21_weight_general_all
by genderid, sort: egen liberal_w_sum = sum(liberal_w)
by genderid, sort: gen p_hat = liberal_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 1.2 if genderid == 3
replace GenderID = 2.2 if genderid == 2
replace GenderID = 3.2 if genderid == 1

gen Party = 1
save "${here}LiberalVote.dta", replace
restore

*** CONSERVATIVE
preserve
drop if genderid == .
drop if vote_2 == .

tab genderid vote_2 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN= sum(cps21_weight_general_all)
by genderid, sort: gen conservative_w = vote_2 * cps21_weight_general_all
by genderid, sort: egen conservative_w_sum = sum(conservative_w)
by genderid, sort: gen p_hat = conservative_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 1 if genderid == 3
replace GenderID = 2 if genderid == 2
replace GenderID = 3 if genderid == 1

gen Party = 2

drop genderid
save "${here}ConservativeVote.dta", replace
restore

*** NDP
preserve
drop if genderid == .
drop if vote_3 == .

tab genderid vote_3 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN= sum(cps21_weight_general_all)
by genderid, sort: gen ndp_w = vote_3 * cps21_weight_general_all
by genderid, sort: egen ndp_w_sum = sum(ndp_w)
by genderid, sort: gen p_hat = ndp_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 0.8 if genderid == 3
replace GenderID = 1.8 if genderid == 2
replace GenderID = 2.8 if genderid == 1

gen Party = 3

drop genderid
save "${here}NDPVote.dta", replace
restore

preserve
use "${here}LiberalVote.dta", clear
append using "${here}ConservativeVote.dta"
append using "${here}NDPVote.dta"

graph twoway ///
	(scatter GenderID p_hat if Party == 1, mcolor(gs12) msymbol(Dh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(scatter GenderID p_hat if Party == 2, mcolor(gs6) msymbol(Sh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(scatter GenderID p_hat if Party == 3, mcolor(black) msymbol(Oh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike lower90 upper90 GenderID if Party == 1, lcolor(gs12) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 1, lcolor(gs12) lwidth(medthin) horizontal) ///
	(rspike lower90 upper90 GenderID if Party == 2, lcolor(gs6) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 2, lcolor(gs6) lwidth(medthin) horizontal) ///
	(rspike lower90 upper90 GenderID if Party == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 3, lcolor(black) lwidth(medthin) horizontal), ///
	yscale(range(0.75 3.25) titlegap(2)) ///
	ytitle("") ///
	ylabel(1 "Nonbinary" 2 "Woman" 3 "Man", labsize(medsmall)) ///
	xscale(range(0 100) titlegap(2)) ///
	xlabel(0(25)100) ///
	legend(order(1 2 3) label(1 "Liberal") label(2 "Conservative") label(3 "NDP")  position(3))
graph export "${here}GenderVoteIntention_Weighted.eps", replace
restore

******************************************************************
*** FIGURE 3: WEIGHTED PARTY IDENTIFICATION, LGBTQ ONLY SAMPLE ***
******************************************************************

*** LIBERAL
preserve
drop if genderid == .
drop if pid_1 == .
keep if lgbtq == 1

tab genderid pid_1 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN = sum(cps21_weight_general_all)
by genderid, sort: gen liberal_w = pid_1 * cps21_weight_general_all
by genderid, sort: egen liberal_w_sum = sum(liberal_w)
by genderid, sort: gen p_hat = liberal_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 1.2 if genderid == 3
replace GenderID = 2.2 if genderid == 2
replace GenderID = 3.2 if genderid == 1

gen Party = 1
save "${here}LiberalPIDLGBTQ.dta", replace
restore

*** CONSERVATIVE
preserve
drop if genderid == .
drop if pid_2 == .
keep if lgbtq == 1

tab genderid pid_2 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN= sum(cps21_weight_general_all)
by genderid, sort: gen conservative_w = pid_2 * cps21_weight_general_all
by genderid, sort: egen conservative_w_sum = sum(conservative_w)
by genderid, sort: gen p_hat = conservative_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 1 if genderid == 3
replace GenderID = 2 if genderid == 2
replace GenderID = 3 if genderid == 1

gen Party = 2

drop genderid
save "${here}ConservativePIDLGBTQ.dta", replace
restore

*** NDP
preserve
drop if genderid == .
drop if pid_3 == .
keep if lgbtq == 1

tab genderid pid_3 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN= sum(cps21_weight_general_all)
by genderid, sort: gen ndp_w = pid_3 * cps21_weight_general_all
by genderid, sort: egen ndp_w_sum = sum(ndp_w)
by genderid, sort: gen p_hat = ndp_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 0.8 if genderid == 3
replace GenderID = 1.8 if genderid == 2
replace GenderID = 2.8 if genderid == 1

gen Party = 3

drop genderid
save "${here}NDPPIDLGBTQ.dta", replace
restore

preserve
use "${here}LiberalPIDLGBTQ.dta", clear
append using "${here}ConservativePIDLGBTQ.dta"
append using "${here}NDPPIDLGBTQ.dta"

graph twoway ///
	(scatter GenderID p_hat if Party == 1, mcolor(gs12) msymbol(Dh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(scatter GenderID p_hat if Party == 2, mcolor(gs6) msymbol(Sh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(scatter GenderID p_hat if Party == 3, mcolor(black) msymbol(Oh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike lower90 upper90 GenderID if Party == 1, lcolor(gs12) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 1, lcolor(gs12) lwidth(medthin) horizontal) ///
	(rspike lower90 upper90 GenderID if Party == 2, lcolor(gs6) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 2, lcolor(gs6) lwidth(medthin) horizontal) ///
	(rspike lower90 upper90 GenderID if Party == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 3, lcolor(black) lwidth(medthin) horizontal), ///
	yscale(range(0.75 3.25) titlegap(2)) ///
	ytitle("") ///
	ylabel(1 "Nonbinary" 2 "Woman" 3 "Man", labsize(medsmall)) ///
	xscale(range(0 100) titlegap(2)) ///
	xlabel(0(25)100) ///
	legend(order(1 2 3) label(1 "Liberal") label(2 "Conservative") label(3 "NDP")  position(3))
graph export "${here}GenderPID_Weighted_LGBTQ.eps", replace
restore

*************************************************************
*** FIGURE 4: WEIGHTED VOTE INTENTIONS, LGBTQ ONLY SAMPLE ***
*************************************************************

*** LIBERAL
preserve
keep if lgbtq == 1
drop if genderid == .
drop if vote_1 == .

tab genderid vote_1 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN = sum(cps21_weight_general_all)
by genderid, sort: gen liberal_w = vote_1 * cps21_weight_general_all
by genderid, sort: egen liberal_w_sum = sum(liberal_w)
by genderid, sort: gen p_hat = liberal_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 1.2 if genderid == 3
replace GenderID = 2.2 if genderid == 2
replace GenderID = 3.2 if genderid == 1

gen Party = 1
save "${here}LiberalVoteLGBTQ.dta", replace
restore

*** CONSERVATIVE
preserve
drop if genderid == .
drop if vote_2 == .
keep if lgbtq == 1

tab genderid vote_2 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN= sum(cps21_weight_general_all)
by genderid, sort: gen conservative_w = vote_2 * cps21_weight_general_all
by genderid, sort: egen conservative_w_sum = sum(conservative_w)
by genderid, sort: gen p_hat = conservative_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 1 if genderid == 3
replace GenderID = 2 if genderid == 2
replace GenderID = 3 if genderid == 1

gen Party = 2

drop genderid
save "${here}ConservativeVoteLGBTQ.dta", replace
restore

*** NDP
preserve
drop if genderid == .
drop if vote_3 == .
keep if lgbtq == 1

tab genderid vote_3 [aweight=cps21_weight_general_all], row

by genderid, sort: egen wN= sum(cps21_weight_general_all)
by genderid, sort: gen ndp_w = vote_3 * cps21_weight_general_all
by genderid, sort: egen ndp_w_sum = sum(ndp_w)
by genderid, sort: gen p_hat = ndp_w_sum / wN
by genderid, sort: gen middle90 = (p_hat + (1.64^2/(2*wN))) / (1 + ((1.64^2)/(wN)))
by genderid, sort: gen lower90 = middle90 - (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen upper90 = middle90 + (1.64*sqrt((p_hat*(1-p_hat)) + ((1.64^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.64^2)/wN))))
by genderid, sort: gen middle95 = (p_hat + (1.96^2/(2*wN))) / (1 + ((1.96^2)/(wN)))
by genderid, sort: gen lower95 = middle95 - (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
by genderid, sort: gen upper95 = middle95 + (1.96*sqrt((p_hat*(1-p_hat)) + ((1.96^2)/(4*wN))))/((sqrt(wN)*(1 + ((1.96^2)/wN))))
collapse p_hat lower90 upper90 lower95 upper95, by(genderid)
replace p_hat = p_hat * 100
replace lower90 = lower90 * 100
replace upper90 = upper90 * 100
replace lower95 = lower95 * 100
replace upper95 = upper95 * 100

gen GenderID = .
replace GenderID = 0.8 if genderid == 3
replace GenderID = 1.8 if genderid == 2
replace GenderID = 2.8 if genderid == 1

gen Party = 3

drop genderid
save "${here}NDPVoteLGBTQ.dta", replace
restore

preserve
use "${here}LiberalVoteLGBTQ.dta", clear
append using "${here}ConservativeVoteLGBTQ.dta"
append using "${here}NDPVoteLGBTQ.dta"

graph twoway ///
	(scatter GenderID p_hat if Party == 1, mcolor(gs12) msymbol(Dh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(scatter GenderID p_hat if Party == 2, mcolor(gs6) msymbol(Sh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(scatter GenderID p_hat if Party == 3, mcolor(black) msymbol(Oh) mlabel(p_hat)  mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike lower90 upper90 GenderID if Party == 1, lcolor(gs12) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 1, lcolor(gs12) lwidth(medthin) horizontal) ///
	(rspike lower90 upper90 GenderID if Party == 2, lcolor(gs6) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 2, lcolor(gs6) lwidth(medthin) horizontal) ///
	(rspike lower90 upper90 GenderID if Party == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike lower95 upper95 GenderID if Party == 3, lcolor(black) lwidth(medthin) horizontal), ///
	yscale(range(0.75 3.25) titlegap(2)) ///
	ytitle("") ///
	ylabel(1 "Nonbinary" 2 "Woman" 3 "Man", labsize(medsmall)) ///
	xscale(range(0 100) titlegap(2)) ///
	xlabel(0(25)100) ///
	legend(order(1 2 3) label(1 "Liberal") label(2 "Conservative") label(3 "NDP")  position(3))
graph export "${here}GenderVoteIntention_Weighted_LGBTQ.eps", replace
restore

**********************************************************
*** GENERATE SURVEY ATTRITION RATES BY GENDER IDENTITY ***
**********************************************************

gen pes = 0
replace pes = 1 if pes21_weight_general_all ~= .
tab genderid pes, row chi

***************************
*** MULTIPLE IMPUTATION ***
***************************

/*
*** POST-ELECTION WAVE
use "GenderGapAnalysis.dta", clear
drop if noncitizen == 1
drop if genderid == 4
recode pt (13=11) (12=11)
recode voteintention (5=6)
recode partyid (5=7) (6=7)
gen votechoice = votechoice2021
recode votechoice (5=6)

set matsize 11000
ice m.sexualid4 m.education o.income born_outside_canada indigenous racialized m.mother_tongue4 ///
	m.partyid m.voteintention m.votechoice ///
	immigration refugees jobs_vs_environment_pes family_values bilingualism equal_rights immigrant_integration immigrant_jobs abortion conversion_therapy international_trade government_intervention income_inequality wealth_gap ///
	i.genderid i.age4 i.pt i.user_language, ///
	saving(MICE2.dta, replace) m(10) seed(123) ///
	cmd(immigration refugees jobs_vs_environment_pes family_values bilingualism equal_rights immigrant_integration immigrant_jobs abortion international_trade government_intervention income_inequality wealth_gap: regress)
*/

****************************************************
*** EXAMINE ISSUE ATTITUDES AND CONSTRUCT SCALES ***
****************************************************

use "${here}MICE2.dta", clear

keep genderid sexualid4 education income born_outside_canada indigenous racialized mother_tongue4 ///
	partyid voteintention votechoice ///
	immigration refugees jobs_vs_environment_pes family_values bilingualism equal_rights immigrant_integration immigrant_jobs abortion conversion_therapy international_trade government_intervention income_inequality wealth_gap ///
	age4 pt user_language cps21_weight_general_all ///
	_mi _mj

mi import ice, automatic clear

*** EXAMINE RELATIONSHIPS AMONG ISSUE ATTITUDES
corr immigration refugees jobs_vs_environment_pes family_values bilingualism equal_rights immigrant_integration immigrant_jobs abortion conversion_therapy international_trade government_intervention income_inequality wealth_gap if _mi_m ~= 0
alpha immigration refugees jobs_vs_environment_pes family_values bilingualism equal_rights immigrant_integration immigrant_jobs abortion conversion_therapy government_intervention income_inequality wealth_gap if _mi_m ~= 0
factor immigration refugees jobs_vs_environment_pes family_values bilingualism equal_rights immigrant_integration immigrant_jobs abortion conversion_therapy government_intervention income_inequality wealth_gap if _mi_m ~= 0

*** GENERATE LEFT-RIGHT SCALE
gen left = (immigration + refugees + jobs_vs_environment_pes + family_values + bilingualism + equal_rights + immigrant_integration + immigrant_jobs + abortion + conversion_therapy + government_intervention + income_inequality + wealth_gap) / 13

*** GENERATE IMMIGRATION SCALE
gen immigration_scale = (immigration + refugees + immigrant_integration + immigrant_jobs) / 4
alpha immigration refugees immigrant_integration immigrant_jobs
factor immigration refugees immigrant_integration immigrant_jobs

*** GENERATE REDISTRIBUTION/INEQUALITY SCALE
gen redistribution_scale = (income_inequality + wealth_gap) / 2
alpha income_inequality wealth_gap

*** GENERATE TRADITIONALISM SCALE
gen traditionalism_scale = (family_values + equal_rights) / 2
alpha family_values equal_rights

*** GENERATE VECTOR OF DUMMY VARIABLES FOR PARTY IDENTIFICATION
tab partyid, gen(pid_)

*** GENERATE VECTOR OF DUMMY VARIABLES FOR VOTE CHOICE
tab votechoice, gen(vote_)

*** RECODE INCOME
recode income (1=2)
gen income7 = income - 1
label variable income7 "Income"

**********************************************
*** TABLE 2: ISSUE ATTITUDES AND POSITIONS ***
**********************************************

mi estimate: reg conversion_therapy i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg immigration i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg refugees i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg immigrant_integration i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg immigrant_jobs i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg income_inequality i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg wealth_gap i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg family_values i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg equal_rights i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg jobs_vs_environment_pes i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg bilingualism i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg abortion i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg government_intervention i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

mi estimate: reg left i.genderid [pweight=cps21_weight_general_all]
mimrgns i.genderid, pwcompare

**********************************************************
*** FIGURE 5: ISSUE ATTITUDES AND PARTY IDENTIFICATION ***
**********************************************************

*** LIBERAL PARTY IDENTIFICATION
** MODEL 1: NO CONTROLS
mi estimate: logit pid_1 i.genderid [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model1IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (1) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 2: PRIOR DEMOGRAPHICS
mi estimate: logit pid_1 i.genderid i.age4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model2IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (2) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 3: ALL DEMOGRAPHICS
mi estimate: logit pid_1 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model3IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (3) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 4: ALL DEMOGRAPHICS + CONVERSION THERAPY
mi estimate: logit pid_1 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt i.conversion_therapy [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model4IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (4) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 5: ALL DEMOGRAPHICS + LEFT-RIGHT SCALE
mi estimate: logit pid_1 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt c.left [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model5IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (5) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

*** GRAPH MODELS FOR LIBERAL PARTY IDENTIFICATION
preserve
use "Model1IssuesLiberalPartyID", clear
append using "Model2IssuesLiberalPartyID"
append using "Model3IssuesLiberalPartyID"
append using "Model4IssuesLiberalPartyID"
append using "Model5IssuesLiberalPartyID"

*** CHECK RELATIVE SIZE OF GAPS
gen BiggerGap2 = 0
replace BiggerGap2 = 1 if abs(Gap2) > abs(Gap1)
tab BiggerGap2

gen BiggerGap3 = 0
replace BiggerGap3 = 1 if abs(Gap3) > abs(Gap1)
tab BiggerGap3

*** DROP THESE VARIABLES FOR RESHAPING
drop BiggerGap2 BiggerGap3

*** RESHAPE FROM MODEL-LEVEL TO MODEL-COMPARISON-LEVEL
reshape long Gap Lower Upper p, i(Model) j(Comparison)

*** LABEL COMPARISONS
label define comparisons 1 "Woman-Man" 2 "Nonbinary-Man" 3 "Nonbinary-Woman"
label values Comparison comparisons

*** CONVERT ESTIMATES FROM PROPORTIONS TO PERCENTAGES
replace Gap = Gap * 100
gen Lower95 = Lower * 100
gen Upper95 = Upper * 100
gen Lower90 = Gap - ((Gap - Lower95) * 0.837)
gen Upper90 = Gap + ((Upper95 - Gap) * 0.837)

*** CODE SIGNIFICANCE AT P < 0.1
gen Sig90 = 0
replace Sig90 = 1 if p < 0.1

gen Sig95 = 0
replace Sig95 = 1 if p < 0.05

*** LOOK AT SIGNIFICANCE BY COMPARISON
tab Comparison Sig90
tab Comparison Sig95
*** ALL GAPS IN LIBERAL PARTY IDENTIFICATION ARE SIGNIFICANT

*** REPLACE NUMBERS AND GENERATE VALUE LABELS
gen ModelLabelled = (Model - 6) * -1

label define models ///
			1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls"
label values ModelLabelled models
			
*** GRAPH COMPARISONS
graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 2, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 2, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 2, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Man") ///
	xlabel(-30(10)10) ///
	xscale(range(-37 15)) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	title("Liberal" "Party Identification", size(medsmall)) ///
	legend(off)
graph save IssuesLiberalPID_NonbinaryVSMan.gph, replace	

graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 3, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 3, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 " " ///
			2 " " ///
			3 " " ///
			4 " " ///
			5 " ") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Woman") ///
	xscale(range(-37 15)) ///
	xlabel(-30(10)10) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	title("Liberal" "Party Identification", size(medsmall)) ///
	fxsize(56.25) ///
	legend(off)
graph save IssuesLiberalPID_NonbinaryVSWoman.gph, replace	
restore

*** CONSERVATIVE PARTY IDENTIFICATION
** MODEL 1: NO CONTROLS
mi estimate: logit pid_2 i.genderid [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model1IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (1) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 2: PRIOR DEMOGRAPHICS
mi estimate: logit pid_2 i.genderid i.age4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model2IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (2) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 3: ALL DEMOGRAPHICS
mi estimate: logit pid_2 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model3IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (3) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 4: ALL DEMOGRAPHICS + CONVERSION THERAPY
mi estimate: logit pid_2 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt i.conversion_therapy [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model4IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (4) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 5: ALL DEMOGRAPHICS + LEFT-RIGHT SCALE
mi estimate: logit pid_2 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt c.left [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model5IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (5) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

*** GRAPH MODELS FOR CONSERVATIVE PARTY IDENTIFICATION
preserve
use "Model1IssuesConservativePartyID", clear
append using "Model2IssuesConservativePartyID"
append using "Model3IssuesConservativePartyID"
append using "Model4IssuesConservativePartyID"
append using "Model5IssuesConservativePartyID"

*** CHECK RELATIVE SIZE OF GAPS
gen BiggerGap2 = 0
replace BiggerGap2 = 1 if abs(Gap2) > abs(Gap1)
tab BiggerGap2

gen BiggerGap3 = 0
replace BiggerGap3 = 1 if abs(Gap3) > abs(Gap1)
tab BiggerGap3

*** DROP THESE VARIABLES FOR RESHAPING
drop BiggerGap2 BiggerGap3

*** RESHAPE FROM MODEL-LEVEL TO MODEL-COMPARISON-LEVEL
reshape long Gap Lower Upper p, i(Model) j(Comparison)

*** LABEL COMPARISONS
label define comparisons 1 "Woman-Man" 2 "Nonbinary-Man" 3 "Nonbinary-Woman"
label values Comparison comparisons

*** CONVERT ESTIMATES FROM PROPORTIONS TO PERCENTAGES
replace Gap = Gap * 100
gen Lower95 = Lower * 100
gen Upper95 = Upper * 100
gen Lower90 = Gap - ((Gap - Lower95) * 0.837)
gen Upper90 = Gap + ((Upper95 - Gap) * 0.837)

*** CODE SIGNIFICANCE AT P < 0.1
gen Sig90 = 0
replace Sig90 = 1 if p < 0.1

gen Sig95 = 0
replace Sig95 = 1 if p < 0.05

*** LOOK AT SIGNIFICANCE BY COMPARISON
tab Comparison Sig90
tab Comparison Sig95
*** ALL GAPS IN CONSERVATIVE PARTY IDENTIFICATION ARE SIGNIFICANT

*** REPLACE NUMBERS AND GENERATE VALUE LABELS
gen ModelLabelled = (Model - 6) * -1

label define models ///
			1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls"
label values ModelLabelled models
			
*** GRAPH COMPARISONS
graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 2, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 2, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 2, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Man") ///
	xlabel(-30(10)10) ///
	xscale(range(-37 15)) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	title("Conservative" "Party Identification", size(medsmall)) ///
	legend(off)
graph save IssuesConservativePID_NonbinaryVSMan.gph, replace	

graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 3, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 3, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 " " ///
			2 " " ///
			3 " " ///
			4 " " ///
			5 " ") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Woman") ///
	xscale(range(-37 15)) ///
	xlabel(-30(10)10) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	title("Conservative" "Party Identification", size(medsmall)) ///
	fxsize(56.25) ///
	legend(off)
graph save IssuesConservativePID_NonbinaryVSWoman.gph, replace	
restore

*** NDP PARTY IDENTIFICATION
** MODEL 1: NO CONTROLS
mi estimate: logit pid_3 i.genderid [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model1IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (1) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 2: PRIOR DEMOGRAPHICS
mi estimate: logit pid_3 i.genderid i.age4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model2IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (2) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 3: ALL DEMOGRAPHICS
mi estimate: logit pid_3 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model3IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (3) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 4: ALL DEMOGRAPHICS + CONVERSION THERAPY
mi estimate: logit pid_3 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt i.conversion_therapy [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model4IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (4) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 5: ALL DEMOGRAPHICS + LEFT-RIGHT SCALE
mi estimate: logit pid_3 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt c.left [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model5IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (5) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

*** GRAPH MODELS FOR NDP PARTY IDENTIFICATION
preserve
use "Model1IssuesNDPPartyID", clear
append using "Model2IssuesNDPPartyID"
append using "Model3IssuesNDPPartyID"
append using "Model4IssuesNDPPartyID"
append using "Model5IssuesNDPPartyID"

*** CHECK RELATIVE SIZE OF GAPS
gen BiggerGap2 = 0
replace BiggerGap2 = 1 if abs(Gap2) > abs(Gap1)
tab BiggerGap2

gen BiggerGap3 = 0
replace BiggerGap3 = 1 if abs(Gap3) > abs(Gap1)
tab BiggerGap3

*** DROP THESE VARIABLES FOR RESHAPING
drop BiggerGap2 BiggerGap3

*** RESHAPE FROM MODEL-LEVEL TO MODEL-COMPARISON-LEVEL
reshape long Gap Lower Upper p, i(Model) j(Comparison)

*** LABEL COMPARISONS
label define comparisons 1 "Woman-Man" 2 "Nonbinary-Man" 3 "Nonbinary-Woman"
label values Comparison comparisons

*** CONVERT ESTIMATES FROM PROPORTIONS TO PERCENTAGES
replace Gap = Gap * 100
gen Lower95 = Lower * 100
gen Upper95 = Upper * 100
gen Lower90 = Gap - ((Gap - Lower95) * 0.837)
gen Upper90 = Gap + ((Upper95 - Gap) * 0.837)

*** CODE SIGNIFICANCE AT P < 0.1
gen Sig90 = 0
replace Sig90 = 1 if p < 0.1

gen Sig95 = 0
replace Sig95 = 1 if p < 0.05

*** LOOK AT SIGNIFICANCE BY COMPARISON
tab Comparison Sig90
tab Comparison Sig95
*** ALL GAPS IN NDP PARTY IDENTIFICATION ARE SIGNIFICANT

*** REPLACE NUMBERS AND GENERATE VALUE LABELS
gen ModelLabelled = (Model - 6) * -1

label define models ///
			1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls"
label values ModelLabelled models
			
*** GRAPH COMPARISONS
graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 2, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 2, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 2, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Man") ///
	xscale(range(-12 65)) ///
	xlabel(-10(10)60) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	title("NDP" "Party Identification", size(medsmall)) ///
	legend(off)
graph save IssuesNDPPID_NonbinaryVSMan.gph, replace	

graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 3, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 3, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 " " ///
			2 " " ///
			3 " " ///
			4 " " ///
			5 " ") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Woman") ///
	xscale(range(-12 65)) ///
	xlabel(-10(10)60) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	fxsize(56.25) ///
	title("NDP" "Party Identification", size(medsmall)) ///
	legend(off)
graph save IssuesNDPPID_NonbinaryVSWoman.gph, replace	
restore

** adjust range of x-axis for Liberal/Conservative

*** COMBINE LIBERAL, CONSERVATIVE, AND NDP GRAPHS
graph combine IssuesLiberalPID_NonbinaryVSMan.gph ///
			  IssuesLiberalPID_NonbinaryVSWoman.gph ///
			  IssuesConservativePID_NonbinaryVSMan.gph ///
			  IssuesConservativePID_NonbinaryVSWoman.gph ///
			  IssuesNDPPID_NonbinaryVSMan.gph ///
			  IssuesNDPPID_NonbinaryVSWoman.gph, ///
			  col(2)
graph export "IssuesPartyIdentification.eps", replace

*** LIBERAL VOTE CHOICE
** MODEL 1: NO CONTROLS
mi estimate: logit vote_1 i.genderid [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model1IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (1) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 2: PRIOR DEMOGRAPHICS
mi estimate: logit vote_1 i.genderid i.age4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model2IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (2) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 3: ALL DEMOGRAPHICS
mi estimate: logit vote_1 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model3IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (3) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 4: ALL DEMOGRAPHICS + CONVERSION THERAPY
mi estimate: logit vote_1 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt i.conversion_therapy [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model4IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (4) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 5: ALL DEMOGRAPHICS + LEFT-RIGHT SCALE
mi estimate: logit vote_1 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt c.left [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model5IssuesLiberalPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (5) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

*** GRAPH MODELS FOR LIBERAL VOTE CHOICE
preserve
use "Model1IssuesLiberalPartyID", clear
append using "Model2IssuesLiberalPartyID"
append using "Model3IssuesLiberalPartyID"
append using "Model4IssuesLiberalPartyID"
append using "Model5IssuesLiberalPartyID"

*** CHECK RELATIVE SIZE OF GAPS
gen BiggerGap2 = 0
replace BiggerGap2 = 1 if abs(Gap2) > abs(Gap1)
tab BiggerGap2

gen BiggerGap3 = 0
replace BiggerGap3 = 1 if abs(Gap3) > abs(Gap1)
tab BiggerGap3

*** DROP THESE VARIABLES FOR RESHAPING
drop BiggerGap2 BiggerGap3

*** RESHAPE FROM MODEL-LEVEL TO MODEL-COMPARISON-LEVEL
reshape long Gap Lower Upper p, i(Model) j(Comparison)

*** LABEL COMPARISONS
label define comparisons 1 "Woman-Man" 2 "Nonbinary-Man" 3 "Nonbinary-Woman"
label values Comparison comparisons

*** CONVERT ESTIMATES FROM PROPORTIONS TO PERCENTAGES
replace Gap = Gap * 100
gen Lower95 = Lower * 100
gen Upper95 = Upper * 100
gen Lower90 = Gap - ((Gap - Lower95) * 0.837)
gen Upper90 = Gap + ((Upper95 - Gap) * 0.837)

*** CODE SIGNIFICANCE AT P < 0.1
gen Sig90 = 0
replace Sig90 = 1 if p < 0.1

gen Sig95 = 0
replace Sig95 = 1 if p < 0.05

*** LOOK AT SIGNIFICANCE BY COMPARISON
tab Comparison Sig90
tab Comparison Sig95
*** ALL GAPS IN LIBERAL VOTE CHOICE ARE SIGNIFICANT

*** REPLACE NUMBERS AND GENERATE VALUE LABELS
gen ModelLabelled = (Model - 6) * -1

label define models ///
			1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls"
label values ModelLabelled models
			
*** GRAPH COMPARISONS
graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 2, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 2, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 2, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Man") ///
	xlabel(-30(10)10) ///
	xscale(range(-37 15)) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	title("Liberal" "Vote Choice", size(medsmall)) ///
	legend(off)
graph save IssuesLiberalVote_NonbinaryVSMan.gph, replace	

graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 3, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 3, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 " " ///
			2 " " ///
			3 " " ///
			4 " " ///
			5 " ") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Woman") ///
	xscale(range(-37 15)) ///
	xlabel(-30(10)10) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	fxsize(56.25) ///
	title("Liberal" "Vote Choice", size(medsmall)) ///
	legend(off)
graph save IssuesLiberalVote_NonbinaryVSWoman.gph, replace	
restore

*** CONSERVATIVE VOTE CHOICE
** MODEL 1: NO CONTROLS
mi estimate: logit vote_2 i.genderid [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model1IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (1) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 2: PRIOR DEMOGRAPHICS
mi estimate: logit vote_2 i.genderid i.age4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model2IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (2) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 3: ALL DEMOGRAPHICS
mi estimate: logit vote_2 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model3IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (3) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 4: ALL DEMOGRAPHICS + CONVERSION THERAPY
mi estimate: logit vote_2 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt i.conversion_therapy [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model4IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (4) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 5: ALL DEMOGRAPHICS + LEFT-RIGHT SCALE
mi estimate: logit vote_2 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt c.left [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model5IssuesConservativePartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (5) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'
*/

*** GRAPH MODELS FOR CONSERVATIVE VOTE CHOICE
preserve
use "Model1IssuesConservativePartyID", clear
append using "Model2IssuesConservativePartyID"
append using "Model3IssuesConservativePartyID"
append using "Model4IssuesConservativePartyID"
append using "Model5IssuesConservativePartyID"

*** CHECK RELATIVE SIZE OF GAPS
gen BiggerGap2 = 0
replace BiggerGap2 = 1 if abs(Gap2) > abs(Gap1)
tab BiggerGap2

gen BiggerGap3 = 0
replace BiggerGap3 = 1 if abs(Gap3) > abs(Gap1)
tab BiggerGap3

*** DROP THESE VARIABLES FOR RESHAPING
drop BiggerGap2 BiggerGap3

*** RESHAPE FROM MODEL-LEVEL TO MODEL-COMPARISON-LEVEL
reshape long Gap Lower Upper p, i(Model) j(Comparison)

*** LABEL COMPARISONS
label define comparisons 1 "Woman-Man" 2 "Nonbinary-Man" 3 "Nonbinary-Woman"
label values Comparison comparisons

*** CONVERT ESTIMATES FROM PROPORTIONS TO PERCENTAGES
replace Gap = Gap * 100
gen Lower95 = Lower * 100
gen Upper95 = Upper * 100
gen Lower90 = Gap - ((Gap - Lower95) * 0.837)
gen Upper90 = Gap + ((Upper95 - Gap) * 0.837)

*** CODE SIGNIFICANCE AT P < 0.1
gen Sig90 = 0
replace Sig90 = 1 if p < 0.1

gen Sig95 = 0
replace Sig95 = 1 if p < 0.05

*** LOOK AT SIGNIFICANCE BY COMPARISON
tab Comparison Sig90
tab Comparison Sig95
*** ALL GAPS IN CONSERVATIVE VOTE CHOICE ARE SIGNIFICANT

*** REPLACE NUMBERS AND GENERATE VALUE LABELS
gen ModelLabelled = (Model - 6) * -1

label define models ///
			1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls"
label values ModelLabelled models
			
*** GRAPH COMPARISONS
graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 2, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 2, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 2, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Man") ///
	xlabel(-30(10)10) ///
	xscale(range(-37 15)) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	title("Conservative" "Vote Choice", size(medsmall)) ///
	legend(off)
graph save IssuesConservativeVote_NonbinaryVSMan.gph, replace	

graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 3, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 3, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 " " ///
			2 " " ///
			3 " " ///
			4 " " ///
			5 " ") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Woman") ///
	xscale(range(-37 15)) ///
	xlabel(-30(10)10) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	fxsize(56.25) ///	
	title("Conservative" "Vote Choice", size(medsmall)) ///
	legend(off)
graph save IssuesConservativeVote_NonbinaryVSWoman.gph, replace	
restore

*** NDP VOTE CHOICE
** MODEL 1: NO CONTROLS
mi estimate: logit vote_3 i.genderid [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model1IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (1) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 2: PRIOR DEMOGRAPHICS
mi estimate: logit vote_3 i.genderid i.age4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model2IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (2) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 3: ALL DEMOGRAPHICS
mi estimate: logit vote_3 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model3IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (3) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 4: ALL DEMOGRAPHICS + CONVERSION THERAPY
mi estimate: logit vote_3 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt i.conversion_therapy [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model4IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (4) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

** MODEL 5: ALL DEMOGRAPHICS + LEFT-RIGHT SCALE
mi estimate: logit vote_3 i.genderid i.age4 i.education c.income7 i.sexualid4 i.born_outside_canada i.indigenous i.racialized i.mother_tongue4 i.pt c.left [pweight = cps21_weight_general_all]
mimrgns i.genderid , predict(pr) pwcompare

tempname memhold
postfile `memhold' Model Gap1 Gap2 Gap3 Lower1 Lower2 Lower3 Upper1 Upper2 Upper3 p1 p2 p3 ///
	using "Model5IssuesNDPPartyID", replace 

	matrix row = r(table_vs)
	local diff1 = row[1,1]
	local diff2 = row[1,2]
	local diff3 = row[1,3]
	local lower1 = row[5,1]
	local lower2 = row[5,2]
	local lower3 = row[5,3]
	local upper1 = row[6,1]
	local upper2 = row[6,2]
	local upper3 = row[6,3]
	local p1 = row[4,1]
	local p2 = row[4,2]
	local p3 = row[4,3]
post `memhold' (5) (`diff1') (`diff2') (`diff3') ///
				(`lower1') (`lower2') (`lower3') ///
				(`upper1') (`upper2') (`upper3') ///
				(`p1') (`p2') (`p3')
postclose `memhold'

*** GRAPH MODELS FOR NDP VOTE CHOICE
preserve
use "Model1IssuesNDPPartyID", clear
append using "Model2IssuesNDPPartyID"
append using "Model3IssuesNDPPartyID"
append using "Model4IssuesNDPPartyID"
append using "Model5IssuesNDPPartyID"

*** CHECK RELATIVE SIZE OF GAPS
gen BiggerGap2 = 0
replace BiggerGap2 = 1 if abs(Gap2) > abs(Gap1)
tab BiggerGap2

gen BiggerGap3 = 0
replace BiggerGap3 = 1 if abs(Gap3) > abs(Gap1)
tab BiggerGap3

*** DROP THESE VARIABLES FOR RESHAPING
drop BiggerGap2 BiggerGap3

*** RESHAPE FROM MODEL-LEVEL TO MODEL-COMPARISON-LEVEL
reshape long Gap Lower Upper p, i(Model) j(Comparison)

*** LABEL COMPARISONS
label define comparisons 1 "Woman-Man" 2 "Nonbinary-Man" 3 "Nonbinary-Woman"
label values Comparison comparisons

*** CONVERT ESTIMATES FROM PROPORTIONS TO PERCENTAGES
replace Gap = Gap * 100
gen Lower95 = Lower * 100
gen Upper95 = Upper * 100
gen Lower90 = Gap - ((Gap - Lower95) * 0.837)
gen Upper90 = Gap + ((Upper95 - Gap) * 0.837)

*** CODE SIGNIFICANCE AT P < 0.1
gen Sig90 = 0
replace Sig90 = 1 if p < 0.1

gen Sig95 = 0
replace Sig95 = 1 if p < 0.05

*** LOOK AT SIGNIFICANCE BY COMPARISON
tab Comparison Sig90
tab Comparison Sig95
*** ALL GAPS IN NDP VOTE CHOICE ARE SIGNIFICANT

*** REPLACE NUMBERS AND GENERATE VALUE LABELS
gen ModelLabelled = (Model - 6) * -1

label define models ///
			1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls"
label values ModelLabelled models
			
*** GRAPH COMPARISONS
graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 2, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 2, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 2, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 "All Demographics + Left-Right Scale" ///
			2 "All Demographics + Conversion Therapy" ///
			3 "All Demographics" ///
			4 "Prior Demographics" ///
			5 "No Controls") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Man") ///
	xscale(range(-12 65)) ///
	xlabel(-10(10)60) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	title("NDP" "Vote Choice", size(medsmall)) ///
	legend(off)
graph save IssuesNDPVote_NonbinaryVSMan.gph, replace	

graph twoway ///
	(scatter ModelLabelled Gap if Comparison == 3, mcolor(black) msymbol(Oh) mlabel(Gap) mlabposition(12) mlabcolor(black) mlabformat(%9.1f)) ///
	(rspike Lower90 Upper90 ModelLabelled if Comparison == 3, lcolor(black) lwidth(medthick) horizontal) ///
	(rspike Lower95 Upper95 ModelLabelled if Comparison == 3, lcolor(black) lwidth(thin) horizontal), ///
	ytitle("") ///
	ylabel(1 " " ///
			2 " " ///
			3 " " ///
			4 " " ///
			5 " ") ///
	yscale(range(0.8 5.2)) ///
	xtitle("Nonbinary-Woman") ///
	xscale(range(-12 65)) ///
	xlabel(-10(10)60) ///
	xline(0, lcolor(gs14) lpattern(solid)) ///
	fxsize(56.25) ///
	title("NDP" "Vote Choice", size(medsmall)) ///
	legend(off)
graph save IssuesNDPVote_NonbinaryVSWoman.gph, replace	
restore

*** COMBINE LIBERAL, CONSERVATIVE, AND NDP GRAPHS
graph combine IssuesLiberalVote_NonbinaryVSMan.gph ///
			  IssuesLiberalVote_NonbinaryVSWoman.gph ///
			  IssuesConservativeVote_NonbinaryVSMan.gph ///
			  IssuesConservativeVote_NonbinaryVSWoman.gph ///
			  IssuesNDPVote_NonbinaryVSMan.gph ///
			  IssuesNDPVote_NonbinaryVSWoman.gph, ///
			  col(2)
graph export "IssuesVoteChoice.eps", replace